package com.shsmi.jc.seed.controller.api;

import com.shsmi.jc.seed.common.MyHttpResponse;
import com.shsmi.jc.seed.security.auth.JwtAuthenticationToken;
import com.shsmi.jc.seed.security.model.UserContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/user")
public class UserController {


    @GetMapping(path = "/me")
    @ResponseBody
    MyHttpResponse whoAmI(JwtAuthenticationToken token) {
        try {
            return MyHttpResponse.of(true, (UserContext) token.getPrincipal(), null, null);
        } catch (Exception e) {
            return MyHttpResponse.of(false, null, e.getMessage(), null);
        }
    }


}
